package com.rc.saas.tenant.service.transfer;

import com.rc.saas.tenant.common.utils.StringUtil;
import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.mapper.transfer.TenantTransferMapper;
import com.rc.saas.tenant.model.tenant.TenantOpenService;
import com.rc.saas.tenant.model.transfer.TenantTransfer;
import com.rc.saas.tenant.service.tenant.TenantOpenServiceService;
import com.rc.saas.tenant.vo.transfer.TenantTransferDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author frog
 * @date 2021/8/21
 */
@Service
public class TenantTransferServiceImpl implements TenantTransferService {

    @Autowired
    private TenantTransferMapper tenantTransferMapper;

    @Autowired
    private TenantOpenServiceService tenantOpenServiceService;

    @Override
    public TenantTransferMapper getMapper() {
        return tenantTransferMapper;
    }

    /*@Override
    public TResponse saveOrUpdateTenantTransfer(TenantTransferDto tenantTransferDTO) {
        TenantTransfer tenantTransfer = tenantTransferMapper.selectByPrimaryKey(tenantTransferDTO.getTenantCode());
        String type = "update";
        if (tenantTransfer == null) {
            type = "save";
            tenantTransfer = new TenantTransfer();
        }


        String transfers = "TRANSFERS";
        TenantOpenService tenantOpenService = tenantOpenServiceService.selectByTypeCode(tenantTransferDTO.getTenantCode(), transfers);
        if (tenantOpenService == null) {
            return TResponse.FAIL("未开通此功能");
        }
        tenantOpenService.setStatus(tenantTransferDTO.getStatus());
        tenantOpenServiceService.updateByPrimaryKeySelective(tenantOpenService);

        if (StringUtil.isNotBlank(tenantTransferDTO.getShow())) {
            String[] showStrings = tenantTransferDTO.getShow().split(",");
            if (showStrings.length == 2) {
                tenantTransfer.setShowForWx("0");
                tenantTransfer.setShowForApp("0");
            } else if (showStrings.length == 1) {
                for (String showString : showStrings) {
                    if ("0".equals(showString)) {
                        tenantTransfer.setShowForWx("0");
                        tenantTransfer.setShowForApp("1");
                    } else if ("1".equals(showString)) {
                        tenantTransfer.setShowForApp("0");
                        tenantTransfer.setShowForWx("1");
                    }
                }
            }

            if (StringUtil.isNotBlank(tenantTransferDTO.getShow())) {
                tenantTransfer.setTransferForWx("0");
                tenantTransfer.setTransferForBankcard("1");
                tenantTransfer.setTransferForAlipay("1");
            } else {
                return TResponse.FAIL("请选择提现途径");
            }
        } else {
            tenantTransfer.setShowForWx("1");
            tenantTransfer.setShowForApp("1");
        }
        if ("1".equals(tenantTransferDTO.getTransferType())) {
            tenantTransfer.setMemberAutoTransfer(tenantTransferDTO.getMemberAutoTransfer());
        } else {
            tenantTransfer.setMemberAutoTransfer("0");
        }
        tenantTransfer.setMemberMonthTransferMax(tenantTransferDTO.getMemberMonthTransferMax());
        tenantTransfer.setMemberTransferMin(tenantTransferDTO.getMemberTransferMin());
        tenantTransfer.setMemberTransferMax(new BigDecimal(2000));
        tenantTransfer.setTransferHint(tenantTransferDTO.getTransferHint());
        tenantTransfer.setIsVerification(tenantTransferDTO.getIsVerification());

        if ("update".equals(type)) {
            //用户每月最多可提现次数 需要设置为空
            tenantTransferMapper.updateByPrimaryKey(tenantTransfer);
        } else {
            //用户每月最多可提现次数 需要设置为空
            tenantTransferMapper.insert(tenantTransfer);
        }
        return TResponse.SUCCESS();
    }*/
}
